<html>
<head><meta charset="utf-8"><title>impl !Sync in stable? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html">impl !Sync in stable?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206370090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370090">(Aug 09 2020 at 00:01)</a>:</h4>
<p>How do I make a type <code>!Sync</code> in stable Rust? Writing <code>impl !Sync for MyType</code> results in:</p>
<div class="codehilite"><pre><span></span><code>error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
</code></pre></div>


<p>There's a reference to <a href="https://github.com/rust-lang/rust/issues/68318">https://github.com/rust-lang/rust/issues/68318</a> , which says nothing about how to do that.</p>



<a name="206370146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370146">(Aug 09 2020 at 00:02)</a>:</h4>
<p>(Context: I have a type that embeds a socket, and it needs to be <code>!Sync</code> because its methods send on the socket and expect to receive a response on the socket, and won't work if called on multiple threads at once.)</p>



<a name="206370480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mikail Bagishov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370480">(Aug 09 2020 at 00:08)</a>:</h4>
<p>What about PhantomData&lt;Cell&lt;()&gt;&gt;?</p>



<a name="206370559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370559">(Aug 09 2020 at 00:10)</a>:</h4>
<p>Ah, I see; that's what it means by "marker types"?</p>



<a name="206370563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370563">(Aug 09 2020 at 00:10)</a>:</h4>
<p>Yeah, I guess I could do that.</p>



<a name="206370595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370595">(Aug 09 2020 at 00:10)</a>:</h4>
<p>So, instead of saying "this is not Sync<code>", I need to embed something that doesn't allow the automatic impl of </code>Sync`.</p>



<a name="206370743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370743">(Aug 09 2020 at 00:13)</a>:</h4>
<p>We should improve that error message (or "just" stabilize !Sync, which I'd be in favor of personally)</p>



<a name="206370795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370795">(Aug 09 2020 at 00:14)</a>:</h4>
<p>I've always found the embedding of PhantomData to be pretty opaque, and I don't know that we lose much by just stabilizing !Sync and !Send (to start)</p>



<a name="206370800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370800">(Aug 09 2020 at 00:14)</a>:</h4>
<p>As in, don't allow negative impls in general, but allow <code>impl !Send</code> and <code>impl !Sync</code> (and any other built-in trait that gets automatically implemented)?</p>



<a name="206370810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370810">(Aug 09 2020 at 00:15)</a>:</h4>
<p>right, yeah -- I think there's reasons we might not want to allow general negative impls</p>



<a name="206370814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370814">(Aug 09 2020 at 00:15)</a>:</h4>
<p>Sure.</p>



<a name="206370815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370815">(Aug 09 2020 at 00:15)</a>:</h4>
<p>(i.e., potentially opens more negative reasoning, like we did for Deref and Pin etc)</p>



<a name="206370818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370818">(Aug 09 2020 at 00:15)</a>:</h4>
<p>but <em>just</em> Send/Sync are already possible by just adding the PhantomData to your type, so I think it's not more expressive</p>



<a name="206370861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206370861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206370861">(Aug 09 2020 at 00:16)</a>:</h4>
<p>especially if you put a requirement like Drop has that the negative impl must be applicable to all instances of the struct</p>



<a name="206371070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206371070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206371070">(Aug 09 2020 at 00:24)</a>:</h4>
<p>Letting users say what they really want instead of telling them to do a dance with the side effects of some other thing in the language is always a good thing.</p>



<a name="206371286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/impl%20%21Sync%20in%20stable%3F/near/206371286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/impl.20!Sync.20in.20stable.3F.html#206371286">(Aug 09 2020 at 00:32)</a>:</h4>
<p><span class="user-mention" data-user-id="223584">@Mikail Bagishov</span> <code>PhantomData&lt;Cell&lt;()&gt;&gt;</code> worked fine. Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>